package com.iotek.ssm.controller;

import com.iotek.ssm.pojo.Train;
import com.iotek.ssm.service.TrainService;
import com.iotek.ssm.util.Util;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/train")
public class TrainController {
    @Autowired
    private TrainService trainService;
    @Autowired
    private Util util;

    @RequestMapping("/updateTrain")
    @ResponseBody
    public Integer updateTrain(Train train){
        train.setLooked(1);
        try {
            trainService.updateTrain(train);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @RequestMapping("/addTrain")
    public String addTrain(Model model,Train train){
        try {
            trainService.addTrain(train);
            util.setJumpDetails(model,"添加成功！","返回首页！","../admin/managePageJump",1);
        } catch (Exception e) {
            e.printStackTrace();
            util.setJumpDetails(model,"添加失败！","返回首页！","../admin/managePageJump",1);
        }
        return "jumpPage";
    }
}
